﻿using UnityEngine;
using System.Collections;
using XLua;

namespace Project {

    public class xLuaInstance : MonoBehaviour
    {

        private static string fixFile = "myHotfix.lua";

        public static void Fixing()
        {

            string FixFilePath = BuildPath._Instance.PCPath_hotFix + fixFile;
            byte[] bytes = FileHelper.Instance.LoadFileBytes(BuildPath._Instance.PCPath_hotFix, fixFile);

            if (bytes != null)
            {

                XluaManager.Instance.luaenv.AddLoader((ref string filename) =>
                {
                    if (filename == "myHotfix")
                    {
                        filename = FixFilePath;
                        return bytes;
                    }

                    return null;
                });
            }

            XluaManager.Instance.luaenv.DoString(@"require 'myHotfix'");

        }

       
    }

}

